/*
** gnl_callbacks.c for libget_next_line in /home/guina_b/
** 
** Made by benoit guina
** Login   <guina_b@epitech.net>
** 
** Started on  Fri Jan 01 00:00:00 2010 benoit guina
** Last update Fri Jan 01 00:00:00 2010 benoit guina
*/

#include <stdlib.h>
#include "gnl_intern.h"

int	_gnl_nodes_strlen(t_gnl_node *node, void *len, void *is_ended)
{
  char	*s;

  s = node->data + node->pos;
  while (*s && *s != '\n')
    {
      if (len)
	(*(int *)len)++;
      s++;
    }
  if (is_ended && (*s == '\n'))
    {
      *(int *)is_ended = 1;
      return (0);
    }
  return (1);
}

int	_gnl_nodes_strcpy(t_gnl_node *node, void *dest, void *start)
{
  char	*s;

  s = node->data + node->pos;
  while (*s && *s != '\n')
    {
      **(char**)dest = *s;
      (*(char**)dest)++;
      s++;
    }
  if (*s == '\n')
    {
      node->pos = ++s - node->data;
      *(t_gnl_node **)start = (*s) ? node : node->n;
      return (0);
    }
  return (1);
}

int	_gnl_nodes_free(t_gnl_node *node, void *start, void *unused)
{
  if (node == (t_gnl_node *)start)
    return (0);
  free(node);
  return (1 || unused);
}
